package com.atguigu.guli.service.vod.controller.api;

import com.aliyuncs.exceptions.ClientException;
import com.atguigu.guli.service.base.exception.GuliException;
import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.base.result.ResultCodeEnum;
import com.atguigu.guli.service.vod.service.VideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "阿里云视频点播")
//@CrossOrigin //跨域
@RestController
@RequestMapping("/api/vod/media")
@Slf4j
public class ApiMediaController {

    @Autowired
    private VideoService videoService;

    //加密视频接口
    @GetMapping("get-play-auth/{videoSourceId}")
    public R getPlayAuth(
            @ApiParam(value = "阿里云视频文件的id",required = true)
            @PathVariable String videoSourceId){

        try {
            String playAuth  = videoService.getPlayAuth(videoSourceId);
            return R.ok().data("playAuth",playAuth);
        } catch (ClientException e) {
            throw new GuliException(ResultCodeEnum.FETCH_PLAYAUTH_ERROR);
        }
    }

    //未加密视频接口
    @GetMapping("get-play-info/{videoSourceId}")
    public R getPlayInfo(
            @ApiParam(value = "阿里云视频文件的id",required = true)
            @PathVariable String videoSourceId){

        try {
            String playInfo  = videoService.getPlayInfo(videoSourceId);
            return R.ok().data("playInfo",playInfo);
        } catch (ClientException e) {
            throw new GuliException(ResultCodeEnum.FETCH_PLAYINFO_ERROR);
        }
    }

}
